package com.hezhiqin.lock;

import java.util.concurrent.CountDownLatch;

/**
 * @program: homeWork
 * @description:
 * @author: hezhiqin
 * @create: 2019-12-29 14:31
 */
public class CountdownlatchDemo extends Thread{


    static CountDownLatch countDownLatch=new CountDownLatch(3);

    public static void main(String[] args) {
        for(int i=0;i<100;i++){
            new CountdownlatchDemo().start();
        }
        countDownLatch.countDown();

    }

    @Override
    public void run() {
        try {
            countDownLatch.await(); //阻塞  3个线程 Thread.currentThread
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //TODO
        System.out.println("ThreadName:"+Thread.currentThread().getName());
    }


//    public static void main(String[] args) throws InterruptedException {
//        CountDownLatch countDownLatch=new CountDownLatch(3);
//        new Thread(()->{
//            System.out.println("Thread1");
//            countDownLatch.countDown(); //3-1=2
//        }).start();
//
//        new Thread(()->{
//            System.out.println("Thread2");
//            countDownLatch.countDown(); //3-2=1
//        }).start();
//
//
//        new Thread(()->{
//            System.out.println("Thread3");
//            countDownLatch.countDown(); //3-3=0
//        }).start();
//
//        countDownLatch.await();
//    }
}
